package com.yanyeori.framework.core.util;

import org.springframework.core.io.ClassPathResource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Banner打印
 *
 * @author chenkuan
 * @date 2023/6/30
 */
public class BannerUtil {

    /**
     * 打印指定resource目录下的banner.txt文件内容到控制台
     * @param resourcePath 项目resource目录下的路径
     */
    public static void printBanner(String resourcePath) {
        InputStream inputStream = null;
        try {
            inputStream = new ClassPathResource(resourcePath).getInputStream();
        } catch (IOException e) {
            System.out.printf("Banner: %s read fail%n", resourcePath);
        }
        if (inputStream != null) {
            new BufferedReader(new InputStreamReader(inputStream)).lines().forEach(System.out::println);
        }
    }
}
